<?php
session_start();
echo "chargement en cours ...";
?>
<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Portail web dédié à la Gestion Administrative et Pédagogique du Master 2 de Recherche Système Complexe UMMISCO">
    <meta name="author" content="DIC1 Génie Info 2013-2014 / ESP Dakar">
    <meta http-equiv="Content-Language" content="fr" />
    <meta name="Keywords" content="ummisco, master2syscom, syscom, master, systeme complexe, recherche" />
    <link rel="shortcut icon" href="../assets/ico/favicon.png">
	<script>document.location.href = '#preinscription';</script>

    <title> UMMISCO - Master 2 SysCom </title>

    <!-- Bootstrap core CSS -->
    <link href="../assets/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../assets/css/main.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/icomoon.css">
    <link href="assets/css/animate-custom.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/bootstrap.css"/>
	<link rel="stylesheet" href="../assets/css/bootstrapValidator.min.css"/>


    
    <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,300,700' rel='stylesheet' type='text/css'>
    
    
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
      <script src="assets/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body data-spy="scroll" data-offset="0" data-target="#navbar-main" >
  	<div id="navbar-main">
      <!-- Fixed navbar -->
    <div class="navbar navbar-inverse navbar-fixed-top" id="header-main">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon icon-shield" style="font-size:30px; color:#3498db;"></span>
          </button>
          <a class="navbar-brand hidden-xs hidden-sm" href="#home"><span class="glyphicon glyphicon-home"></span></a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
	      	<li><a href="../index.php#home" class="smoothScroll">Accueil</a></li>
			<li> <a href="../index.php#about" class="smoothScroll"> Présentation </a></li>
			<li> <a href="../index.php#direction" class="smoothScroll"> Direction</a></li>
			<li> <a href="../index.php#recherche" class="smoothScroll"> Recherche </a></li>
			<li> <a href="../index.php#formation" class="smoothScroll"> Formation </a></li>
			<li> <a href="../index.php#pre-inscription" class="smoothScroll"> Pré-inscription</a></li>
			<li> <a href="../index.php#contact" class="smoothScroll"> Contact</a></li>
		 </ul>
		 <ul class="nav pull-right">
                      <li class="divider-vertical"></li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-user"> </i>&nbsp;<?php  echo $_SESSION['adminPrenom'] ?> <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                          <li><a href="index.php"> Menu Admin &nbsp;<i class= "glyphicon glyphicon-edit"></i></a></li>
                          <li class="divider"></li>
                          <li><a href="deconnexion.php">Se déconnecter&nbsp;<i class="glyphicon glyphicon-off"></i>  </a> </li>
                        </ul>
                      </li>
                    </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    </div>

  
  
		<!-- ==== HEADERWRAP ==== -->
	    <div id="headerwrap" id="home" name="home">
			<header class="clearfix">
	  		 		<!--
	  		 		<h1><span class="icon icon-shield"></span></h1>
	  		 		<p>U M M I S C O</p>
	  		 		<p>Unité de Modélisation Mathématique et Informatique de Systèmes COmplexes</p>
	  		 		-->
	  		</header>	    
	    </div><!-- /headerwrap -->
		
		<div class="container" name="pre-inscription" id="pre-inscription">
				<a name="preinscription"></a>
				<div class="row white">
				
				 <div class="panel panel-info">
			      <div class="panel-heading">
			        <h3 class="panel-title"> <h1 class="centered"> Administration des pré-inscriptions </h1></h3>
			      </div>
			      <div class="panel-body" align="center">
						<h3> Validation des pré-inscriptions </h3>
			      </div>
			    </div>

		    <div class="well">
	 		 <div class="bs-example">
			    <div class="panel panel-default">
			      <div class="panel-heading centered"> Liste des Candidats à la pré-inscription </div>
			      <form action="valider.php" method="post">
				      <table class="table"  >
				        <thead >
				          <tr class="bg-info">
				            <th>ID</th>
				            <th>Prénom</th>
				            <th>Nom</th>
				            <th>Date de Naiss</th>
				            <th>Lieu de Naiss</th>
				            <th>Email</th>
				            <th>Statut</th>
				            <th>Etat</th>
				          </tr>
				        </thead>
				        <tbody>
				        	<?php
				        		 $tab = array();
				        		 $x=0;
						         include_once '../assets/config/mysql.php';
								 // === Mise à jour de la table diplome
								 $result= mysqli_query($db, "SELECT * from candidat;")  or die("Error: ".mysqli_error($db));
								 while($row = mysqli_fetch_array($result,MYSQLI_NUM))  
									{
									   $tab[$x]=$row[0];
									   $x++;
									   $result2= mysqli_query($db, "SELECT statut from preinscription where ID_CANDIDAT=".$row[0].";") or die("Error: ". mysqli_error($db));
							   		   $row2=mysqli_fetch_array($result2,MYSQLI_NUM);
									   echo "
									   		<tr>
								            <td>".$row[0]."</td>
								            <td>".$row[1]."</td>
								            <td>".$row[2]."</td>
								            <td>".$row[7]."</td>
								            <td>".$row[8]."</td>
								            <td>".$row[6]."</td>
								            <td>
								            	<label class='btn btn-success'>
											    	<input type='radio' name='".$row[0]."' id='".$row[0]."' value='accepté'> Accepter
											  	</label>
											  	<label class='btn btn-info'>
											    	<input type='radio' name='".$row[0]."' id='".$row[0]."' value='refusé'> Refuser
											  	</label>
											</td>
											<td>
											  	<label class='btn btn-primary'>
											    	$row2[0]
											  	</label>
								            </td>
								          </tr>
									   ";
									}  
						 ?>
						 <tr></tr>
		        </tbody>
		      </table>
		      </br>
		      </br>
		        <div class="centered">
	                <button class='btn btn-primary btn-lg btn-block' type='submit'>VALIDER</button>
				</div>
		      </form>
		      <div class="centered">
			      <ul class="pagination pagination-lg">
			        <li><a href="#">&laquo;</a></li>
			        <li><a href="#">1</a></li>
			        <li><a href="#">2</a></li>
			        <li><a href="#">3</a></li>
			        <li><a href="#">4</a></li>
			        <li><a href="#">5</a></li>
			        <li><a href="#">&raquo;</a></li>
			      </ul>
			    </div>
		    </div>
	</div>
	</div>
	</div>
	</div>
	<?php
		$x1=0;
		$x2=0;
		if (isset($_POST[''.$tab[0].''])){
			for ($x=0; $x<count($tab); $x++) {
				if ($_POST[''.$tab[$x].'']=='accepté'){
					$_SESSION['acceptes'][$x1]=$tab[$x];
					$x1++;
					mysqli_query ($db, "UPDATE preinscription SET STATUT='accepté' where ID_CANDIDAT=".$tab[$x].";") or die("Error: ". mysqli_error($db));
				} else {
					$_SESSION['refuses'][$x2]=$tab[$x];
					$x2++;
					mysqli_query ($db, "UPDATE preinscription SET STATUT='refusé' where ID_CANDIDAT=".$tab[$x].";") or die("Error: ". mysqli_error($db));
					}
			}
			for ($x=0; $x<$x1; $x++) {
				 $result= mysqli_query($db, "SELECT email, nom, prenom from candidat where ID_CANDIDAT=".$_SESSION['acceptes'][$x].";");
				 $row = mysqli_fetch_array($result,MYSQLI_NUM);
				 $_SESSION['emailAccepte'][$x]=$row[0];
				 $_SESSION['nomAccepte'][$x]=$row[1];
				 $_SESSION['prenomAccepte'][$x]=$row[2];
				 
			}
			
			for ($x=0; $x<$x2; $x++) {
				 $result= mysqli_query($db, "SELECT email, nom, prenom from candidat where ID_CANDIDAT=".$_SESSION['refuses'][$x].";");
				 $row = mysqli_fetch_array($result,MYSQLI_NUM);
				 $_SESSION['emailRefuse'][$x]=$row[0];
				 $_SESSION['nomRefuse'][$x]=$row[1];
				 $_SESSION['prenomRefuse'][$x]=$row[2];
				 
			}
			
			die("<meta http-equiv='refresh' content=0;URL='message.php'>");
		}
		
	?>
		<div id="footerwrap">
			<div class="container">
				<h4>Created by <a href="http://code.google.com/p/master2syscom" target="_blank">DIC1 Info ESP</a> - Copyright 2014</h4>
			</div>
		</div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
		
	<script src="assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/modernizr.custom.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrapValidator.min.js"></script>
	
	<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../assets/js/retina.js"></script>
	<script type="text/javascript" src="../assets/js/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="../assets/js/smoothscroll.js"></script>
	<script type="text/javascript" src="../assets/js/jquery-func.js"></script>
	<script>	
		$(document).ready(function() {
	    $('.col-lg-12').bootstrapValidator({
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	            email: {
	                validators: {
	                    notEmpty: {
	                        message: 'The email is required and cannot be empty'
	                    },
	                    emailAddress: {
	                        message: 'The input is not a valid email address'
	                    }
	                }
	            }
	        }
	    });
	});
</script>
  </body>
</html>